const util = require('../../resource/util/util.js');
const formatLocation = util.formatLocation;
Page({
  onShareAppMessage(){
    return{
      title: '选择位置',
      path: 'page/API/pages/choose-location/choose-location'
    }
  },
  data:{
    hasLocation: false,
  },
  onLoad:function(local){
    const that = this;
    wx.chooseLocation({
      success(res){
        let pages = getCurrentPages();
        let prevPage = pages[pages.length - 2];
        if(local.type){
          prevPage.setData({
            type: local.type,
            localhost: res
          });
        }else{
          prevPage.setData({
            localhost: res
          });
        }
        that.setData({
          hasLocation: true,
          location: formatLocation(res.longitude, res.latitude),
          locationAddress: res.address
        })
        wx.navigateBack({
          delta: 1
        })
      },
      cancel:function(res){
        wx.navigateBack({
          delta: 1
        })
      }
    })
  }
})
